package charstream;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class CharStreamDemo1 {
    public static void main(String[] args) throws UnsupportedEncodingException {
        //method1();

        // String(byte[]bytes)://通过使用平台的默认字符集解码指定的字节数组来构造新的  string
        // String(byte[l bytes,string charsetName)://通过指定的字符集解码指定的字节数组来构造新的 string
        byte[] bytes1={-23, -69, -111, -23, -87, -84, -25, -88, -117, -27, -70, -113, -27, -111, -104};
        byte[] bytes2={-70, -38, -62, -19, -77, -52, -48, -14, -44, -79};
        System.out.println(new String(bytes1));
        System.out.println(new String(bytes2,"gbk"));

    }

    private static void method1() throws UnsupportedEncodingException {
        // byteTl getBytes():使用平台的默认字符集将该 string编码为一系列字节，将结果存储到新的字节数组中
        // byte[] getBytes(string charsetName):使用指定的字符集将该 string编码为一系列字节，将结果存储到新的字节数组中
        String s= "黑马程序员";
        byte[] bytes1 = s.getBytes();
        byte[] bytes2 = s.getBytes("GBK");
        System.out.println(Arrays.toString(bytes1));
        System.out.println(Arrays.toString(bytes2));
    }
}
